<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="google-site-verification" content="yF8HXsFuCTrePDFRnSkN2kkzV2ypBjtywzXsfVXOOV8">
  <meta name="baidu-site-verification" content="VxrVAiQAZ9">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yang0033.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":true,"preload":true},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="百度地图集成申请AK(注意选择应用类型为iOS，安全码即项目的bundle ID)开发前注意事项 注意事项：">
<meta property="og:type" content="article">
<meta property="og:title" content="百度地图集成">
<meta property="og:url" content="http://yang0033.gitee.io/2015/12/04/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%E9%9B%86%E6%88%90/index.html">
<meta property="og:site_name" content="SuperYang&#96;s Blog">
<meta property="og:description" content="百度地图集成申请AK(注意选择应用类型为iOS，安全码即项目的bundle ID)开发前注意事项 注意事项：">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2015-12-04T12:32:34.000Z">
<meta property="article:modified_time" content="2020-07-09T07:56:10.582Z">
<meta property="article:author" content="SuperYang">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yang0033.gitee.io/2015/12/04/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%E9%9B%86%E6%88%90/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>百度地图集成 | SuperYang`s Blog</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-71812998-3"></script>
    <script>
      if (CONFIG.hostname === location.hostname) {
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-71812998-3');
      }
    </script>


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?8ff3295288514de6f89f314c23ee40ab";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">SuperYang`s Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">落魄程序员在线炒饭</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-message">

    <a href="/message/" rel="section"><i class="fa fa-music fa-fw"></i>留言板 | Music</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2015/12/04/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%E9%9B%86%E6%88%90/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          百度地图集成
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2015-12-04 20:32:34" itemprop="dateCreated datePublished" datetime="2015-12-04T20:32:34+08:00">2015-12-04</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-07-09 15:56:10" itemprop="dateModified" datetime="2020-07-09T15:56:10+08:00">2020-07-09</time>
              </span>

          
            <span id="/2015/12/04/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%E9%9B%86%E6%88%90/" class="post-meta-item leancloud_visitors" data-flag-title="百度地图集成" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2015/12/04/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%E9%9B%86%E6%88%90/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2015/12/04/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%E9%9B%86%E6%88%90/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>5.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="百度地图集成"><a href="#百度地图集成" class="headerlink" title="百度地图集成"></a>百度地图集成</h1><h2 id="申请AK-注意选择应用类型为iOS，安全码即项目的bundle-ID"><a href="#申请AK-注意选择应用类型为iOS，安全码即项目的bundle-ID" class="headerlink" title="申请AK(注意选择应用类型为iOS，安全码即项目的bundle ID)"></a><a href="http://developer.baidu.com/map/index.php?title=iossdk/guide/key" target="_blank" rel="noopener">申请AK(注意选择应用类型为iOS，安全码即项目的bundle ID)</a></h2><h2 id="开发前注意事项"><a href="#开发前注意事项" class="headerlink" title="开发前注意事项"></a>开发前注意事项</h2><ul>
<li>注意事项：<a id="more"></a> <ul>
<li><strong>编译环境：</strong>由于静态库用C++编写，所以项目中至少有一个.mm文件，或者直接修改编译方式为Xcode的Project -&gt; Edit Active Target -&gt; Build -&gt; GCC4.2 - Language -&gt; Compile Sources As -&gt; objective-C++</li>
<li><strong>xib编译支持：</strong>如果在xib中使用BMKMapView，代码中没有用，编译器链接时不会链接对应符号，则需要Xcode的Project -&gt; Edit Active Target -&gt; Build -&gt; Linking -&gt; Other Linker Flags中添加-ObjC</li>
<li><strong>授权码更替：</strong>新旧授权码不可混用，区分版本从v2.0.1开始，之后才开始用新key</li>
<li><strong>iOS9网络请求适配：</strong>“Info.plist”中设置<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">key</span>&gt;</span>NSAppTransportSecurity<span class="tag">&lt;/<span class="name">key</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;<span class="name">dict</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">key</span>&gt;</span>NSAllowsArbitraryLoads<span class="tag">&lt;/<span class="name">key</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">true</span>/&gt;</span></span><br><span class="line">   <span class="tag">&lt;/<span class="name">dict</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
<li><strong>iOS9应用间跳转适配：</strong>“Info.plist”中设置<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">key</span>&gt;</span>LSApplicationQueriesSchemes<span class="tag">&lt;/<span class="name">key</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">array</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">string</span>&gt;</span>baidumap<span class="tag">&lt;/<span class="name">string</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">array</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
<li><strong>管理地图的生命周期：</strong>为了让项目中的BMKMapView在同一时刻接受回调，在控制器的viewWillAppear、viewWillDisappear方法中调用BMKMapView的对应的方法，并处理delegate，代码如下：<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">    - (<span class="keyword">void</span>)viewWillAppear:(<span class="built_in">BOOL</span>)animated      </span><br><span class="line">&#123;      </span><br><span class="line">    [_mapView viewWillAppear];      </span><br><span class="line">    _mapView.delegate = <span class="keyword">self</span>; <span class="comment">// 此处记得不用的时候需要置nil，否则影响内存的释放      </span></span><br><span class="line">&#125;      </span><br><span class="line">	- (<span class="keyword">void</span>)viewWillDisappear:(<span class="built_in">BOOL</span>)animated      </span><br><span class="line">&#123;      </span><br><span class="line">        [_mapView viewWillDisappear];      </span><br><span class="line">      _mapView.delegate = <span class="literal">nil</span>; <span class="comment">// 不用时，置nil      </span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><strong>iOS8获取GPS描述权限兼容：</strong> 需要在info.plist里添加（以下二选一，两个都添加默认使用NSLocationWhenInUseUsageDescription）：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">NSLocationWhenInUseUsageDescription ，</span><br><span class="line">允许在前台使用时获取GPS的描述</span><br><span class="line">NSLocationAlwaysUsageDescription ，允许永久使用GPS的描述</span><br></pre></td></tr></table></figure></li>
<li><strong>Xcode6配置：</strong>需要在info.plist中添加：Bundle display name ，且其值不能为空（Xcode6新建的项目没有此配置，若没有会造成manager start failed）</li>
<li><strong>APP包体积：</strong>百度地图iOS SDK v2.5.0起，对arm64进行了支持适配，开发包体积有所增加。但根据开发者在研发过程中的选择，最终生成的APP体积并不会发生较大的变化。</li>
<li><strong>mapapi.bundle处理：</strong>确认项目中添加mapapi.bundle文件以及添加方法正确，不能删除或随意更改其中files文件夹下的内容：<br>注：mapapi.bundle中存储了定位、默认大头针标注View及路线关键点的资源图片，还存储了矢量地图绘制必需的资源文件。如果您不需要使用内置的图片显示功能，则可以删除bundle文件中的image文件夹。您也可以根据具体需求任意替换或删除该bundle中image文件夹的图片文件。添加方式：将mapapi.bundle拷贝到您的工程目录，直接将该bundle文件托拽至Xcode工程左侧的Groups&amp;Files中即可。若您需要替换定位、指南针的图标，请保留原文件名称，否则不显示替换的新图片，默认大头针标注与路线关键点的新图片名称可自定义名称。</li>
<li><strong>BMKManager对象的生命周期管理：</strong>注意BMKManager对象的生命周期管理，在使用地图SDK期间不能释放该对象，尤其在arc情况下注意避免提前被自动释放，否则，该对象一旦被释放，网络模块将不可用，地图无法加载，检索失败。</li>
<li><strong>前后台切换：</strong>app在前后台切换时，需要使用下面的代码停止地图的渲染和openGL的绘制：<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="keyword">void</span>)applicationWillResignActive:(<span class="built_in">UIApplication</span> *)application &#123;</span><br><span class="line">    [BMKMapView willBackGround];<span class="comment">//当应用即将后台时调用，停止一切调用opengl相关的操作</span></span><br><span class="line">&#125;</span><br><span class="line">- (<span class="keyword">void</span>)applicationDidBecomeActive:(<span class="built_in">UIApplication</span> *)application &#123;</span><br><span class="line">    [BMKMapView didForeGround];<span class="comment">//当应用恢复前台状态时调用，回复地图的渲染和opengl相关的操作</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="配置开发环境"><a href="#配置开发环境" class="headerlink" title="配置开发环境"></a>配置开发环境</h2><h3 id="1-自动配置-framework-CocoaPods"><a href="#1-自动配置-framework-CocoaPods" class="headerlink" title="1 自动配置.framework(CocoaPods)"></a>1 自动配置.framework(CocoaPods)</h3><h4 id="1-1-安装CocoaPods（步骤略）"><a href="#1-1-安装CocoaPods（步骤略）" class="headerlink" title="1.1 安装CocoaPods（步骤略）"></a>1.1 安装CocoaPods（步骤略）</h4><h4 id="1-2-创建并编辑Podfile"><a href="#1-2-创建并编辑Podfile" class="headerlink" title="1.2 创建并编辑Podfile"></a>1.2 创建并编辑Podfile</h4></li>
</ul>
</li>
</ul>
<figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">pod <span class="string">'BaiduMapKit'</span> <span class="comment">#百度地图SDK</span></span><br><span class="line"><span class="string">``</span><span class="string">` </span></span><br><span class="line"><span class="string">编辑完成之后控制台运行</span></span><br><span class="line"><span class="string">	</span></span><br><span class="line"><span class="string">`</span><span class="string">``</span>ruby</span><br><span class="line">pod install</span><br></pre></td></tr></table></figure>

<ul>
<li>优点：使用简单，傻瓜式配置</li>
<li>缺点：只能导入全功能包，不能自己按需求定制，打包后APP体积较大    </li>
</ul>
<h4 id="2-手动配置-framework"><a href="#2-手动配置-framework" class="headerlink" title="2 手动配置.framework"></a>2 手动配置.framework</h4><h4 id="2-1-按需导入framework"><a href="#2-1-按需导入framework" class="headerlink" title="2.1 按需导入framework"></a>2.1 按需导入framework</h4><h5 id="2-1-1-首先需要导入基本包"><a href="#2-1-1-首先需要导入基本包" class="headerlink" title="2.1.1 首先需要导入基本包"></a>2.1.1 首先需要导入基本包</h5><ul>
<li>BaiduMapAPI_Base.framework，之后导入的其他功能包必须与基本包版本保持一致</li>
<li>将所需的BaiduMapAPI_<strong>.framework拷贝到工程所在文件夹下。<br>在 TARGETS-&gt;Build Phases-&gt; Link Binary With Libaries中点击“+”按钮，在弹出的窗口中点击“Add Other”按钮，选择BaiduMapAPI_</strong>.framework添加到工程中。</li>
<li>注: 静态库中采用Objective-C++实现，因此需要您保证您工程中至少有一个.mm后缀的源文件(您可以将任意一个.m后缀的文件改名为.mm)，或者在工程属性中指定编译方式，即将Xcode的Project -&gt; Edit Active Target -&gt; Build -&gt; GCC4.2 - Language -&gt; Compile Sources As设置为”Objective-C++”</li>
</ul>
<h5 id="2-1-2-引入所需系统库"><a href="#2-1-2-引入所需系统库" class="headerlink" title="2.1.2 引入所需系统库"></a>2.1.2 引入所需系统库</h5><p>百度地图SDK中提供了定位功能和动画效果，v2.0.0版本开始使用OpenGL渲染，因此您需要在您的Xcode工程中引入CoreLocation.framework和QuartzCore.framework、OpenGLES.framework、SystemConfiguration.framework、CoreGraphics.framework、Security.framework、<strong>libsqlite3.0.tbd（xcode7以前为 libsqlite3.0.dylib）、CoreTelephony.framework 、libstdc++.6.0.9.tbd（xcode7以前为libstdc++.6.0.9.dylib）</strong>。<br>（注：加粗标识的系统库为v2.9.0新增的系统库，使用v2.9.0及以上版本的地图SDK，务必增加导入这3个系统库。）<br>添加方式：在Xcode的Project -&gt; Active Target -&gt;Build Phases -&gt;Link Binary With Libraries，添加这几个系统库即可。</p>
<h5 id="2-1-3-环境配置"><a href="#2-1-3-环境配置" class="headerlink" title="2.1.3 环境配置"></a>2.1.3 环境配置</h5><p>在TARGETS-&gt;Build Settings-&gt;Other Linker Flags 中添加-ObjC。</p>
<h5 id="2-1-4-引入mapapi-bundle资源文件"><a href="#2-1-4-引入mapapi-bundle资源文件" class="headerlink" title="2.1.4 引入mapapi.bundle资源文件"></a>2.1.4 引入mapapi.bundle资源文件</h5><p>如果使用了基础地图功能，需要添加该资源，否则地图不能正常显示mapapi.bundle中存储了定位、默认大头针标注View及路线关键点的资源图片，还存储了矢量地图绘制必需的资源文件。如果您不需要使用内置的图片显示功能，则可以删除bundle文件中的image文件夹。您也可以根据具体需求任意替换或删除该bundle中image文件夹的图片文件。<br>方法：选中工程名，在右键菜单中选择Add Files to “工程名”…，从BaiduMapAPI_Map.framework||Resources文件中选择mapapi.bundle文件，并勾选“Copy items if needed”复选框，单击“Add”按钮，将资源文件添加到工程中。</p>
<h5 id="2-1-5-引入头文件"><a href="#2-1-5-引入头文件" class="headerlink" title="2.1.5 引入头文件"></a>2.1.5 引入头文件</h5><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#import <span class="meta-string">&lt;BaiduMapAPI_Base/BMKBaseComponent.h&gt;//引入base相关所有的头文件</span></span></span><br><span class="line"> </span><br><span class="line"><span class="meta">#import <span class="meta-string">&lt;BaiduMapAPI_Map/BMKMapComponent.h&gt;//引入地图功能所有的头文件</span></span></span><br><span class="line"> </span><br><span class="line"><span class="meta">#import <span class="meta-string">&lt;BaiduMapAPI_Search/BMKSearchComponent.h&gt;//引入检索功能所有的头文件</span></span></span><br><span class="line"> </span><br><span class="line"><span class="meta">#import <span class="meta-string">&lt;BaiduMapAPI_Cloud/BMKCloudSearchComponent.h&gt;//引入云检索功能所有的头文件</span></span></span><br><span class="line"> </span><br><span class="line"><span class="meta">#import <span class="meta-string">&lt;BaiduMapAPI_Location/BMKLocationComponent.h&gt;//引入定位功能所有的头文件</span></span></span><br><span class="line"> </span><br><span class="line"><span class="meta">#import <span class="meta-string">&lt;BaiduMapAPI_Utils/BMKUtilsComponent.h&gt;//引入计算工具所有的头文件</span></span></span><br><span class="line"> </span><br><span class="line"><span class="meta">#import <span class="meta-string">&lt;BaiduMapAPI_Radar/BMKRadarComponent.h&gt;//引入周边雷达功能所有的头文件</span></span></span><br><span class="line"> </span><br><span class="line"><span class="meta">#import <span class="meta-string">&lt; BaiduMapAPI_Map/BMKMapView.h&gt;//只引入所需的单个头文件</span></span></span><br></pre></td></tr></table></figure>
<h2 id="Hello-BaiduMap"><a href="#Hello-BaiduMap" class="headerlink" title="Hello BaiduMap"></a>Hello BaiduMap</h2><h3 id="1-初始化地图"><a href="#1-初始化地图" class="headerlink" title="1 初始化地图"></a>1 初始化地图</h3><p>在您的AppDelegate.h文件中添加BMKMapManager的定义</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">AppDelegate</span> : <span class="title">UIResponder</span> &lt;<span class="title">UIApplicationDelegate</span>&gt;</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">UINavigationController</span> *navigationController;</span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) BMKMapManager *mapManager;</span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">strong</span>, <span class="keyword">nonatomic</span>) <span class="built_in">UIWindow</span> *window;</span><br><span class="line"><span class="keyword">@end</span></span><br></pre></td></tr></table></figure>
<p>在您的AppDelegate.m文件中添加对BMKMapManager的初始化，并填入您申请的授权Key，示例如下</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="built_in">BOOL</span>)application:(<span class="built_in">UIApplication</span> *)application   </span><br><span class="line">didFinishLaunchingWithOptions:(<span class="built_in">NSDictionary</span> *)launchOptions &#123;           <span class="comment">// Override point for customization after application launch.</span></span><br><span class="line">    _mapManager = [[BMKMapManager alloc]init];</span><br><span class="line">    <span class="comment">// 如果要关注网络及授权验证事件，请设定     generalDelegate参数</span></span><br><span class="line">    <span class="built_in">BOOL</span> ret = [_mapManager start:<span class="string">@"在此输入你的AK"</span>  generalDelegate:<span class="literal">nil</span>];</span><br><span class="line">    <span class="keyword">if</span> (!ret) &#123;</span><br><span class="line">        <span class="built_in">NSLog</span>(<span class="string">@"manager start failed!"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// Add the navigation controller's view to the window and display.</span></span><br><span class="line">    <span class="keyword">self</span>.window = [[<span class="built_in">UIWindow</span> alloc] initWithFrame:[[<span class="built_in">UIScreen</span> mainScreen] bounds]];</span><br><span class="line">    ViewController *rootVC = [ViewController new];</span><br><span class="line">    <span class="keyword">self</span>.navigationController = [[<span class="built_in">UINavigationController</span> alloc] initWithRootViewController:rootVC];</span><br><span class="line">    <span class="keyword">self</span>.window.rootViewController = <span class="keyword">self</span>.navigationController;</span><br><span class="line">    [<span class="keyword">self</span>.window makeKeyAndVisible];</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">YES</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="https://www.jianshu.com/u/f37a8f0ba6f8">
            <span class="icon">
              <i class="fas fa-book"></i>
            </span>

            <span class="label">简书</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2015/11/29/ios%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96_---_%E7%95%8C%E9%9D%A2%E5%8D%A1%E9%A1%BF%E4%BA%A7%E7%94%9F%E7%9A%84%E5%8E%9F%E5%9B%A0%E5%92%8C%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/" rel="prev" title="iOS性能优化 --- 界面卡顿产生的原因和解决方案">
      <i class="fa fa-chevron-left"></i> iOS性能优化 --- 界面卡顿产生的原因和解决方案
    </a></div>
      <div class="post-nav-item">
    <a href="/2016/01/04/objective-c%E9%94%99%E8%AF%AF%E6%A8%A1%E5%9E%8B/" rel="next" title="Objective-C错误模型">
      Objective-C错误模型 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#百度地图集成"><span class="nav-number">1.</span> <span class="nav-text">百度地图集成</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#申请AK-注意选择应用类型为iOS，安全码即项目的bundle-ID"><span class="nav-number">1.1.</span> <span class="nav-text">申请AK(注意选择应用类型为iOS，安全码即项目的bundle ID)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#开发前注意事项"><span class="nav-number">1.2.</span> <span class="nav-text">开发前注意事项</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#配置开发环境"><span class="nav-number">1.3.</span> <span class="nav-text">配置开发环境</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-自动配置-framework-CocoaPods"><span class="nav-number">1.3.1.</span> <span class="nav-text">1 自动配置.framework(CocoaPods)</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-1-安装CocoaPods（步骤略）"><span class="nav-number">1.3.1.1.</span> <span class="nav-text">1.1 安装CocoaPods（步骤略）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#1-2-创建并编辑Podfile"><span class="nav-number">1.3.1.2.</span> <span class="nav-text">1.2 创建并编辑Podfile</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-手动配置-framework"><span class="nav-number">1.3.1.3.</span> <span class="nav-text">2 手动配置.framework</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-按需导入framework"><span class="nav-number">1.3.1.4.</span> <span class="nav-text">2.1 按需导入framework</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#2-1-1-首先需要导入基本包"><span class="nav-number">1.3.1.4.1.</span> <span class="nav-text">2.1.1 首先需要导入基本包</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-1-2-引入所需系统库"><span class="nav-number">1.3.1.4.2.</span> <span class="nav-text">2.1.2 引入所需系统库</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-1-3-环境配置"><span class="nav-number">1.3.1.4.3.</span> <span class="nav-text">2.1.3 环境配置</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-1-4-引入mapapi-bundle资源文件"><span class="nav-number">1.3.1.4.4.</span> <span class="nav-text">2.1.4 引入mapapi.bundle资源文件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-1-5-引入头文件"><span class="nav-number">1.3.1.4.5.</span> <span class="nav-text">2.1.5 引入头文件</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Hello-BaiduMap"><span class="nav-number">1.4.</span> <span class="nav-text">Hello BaiduMap</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-初始化地图"><span class="nav-number">1.4.1.</span> <span class="nav-text">1 初始化地图</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="SuperYang"
      src="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
  <p class="site-author-name" itemprop="name">SuperYang</p>
  <div class="site-description" itemprop="description">牛肉炒饭不要香菜，老板收钱</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">39</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">5</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">31</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yangchao0033" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yangchao0033" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:ygrfwyc@gmail.com" title="E-Mail → mailto:ygrfwyc@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/yangchao0033" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;yangchao0033" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.jianshu.com/u/f37a8f0ba6f8" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;f37a8f0ba6f8" rel="noopener" target="_blank"><i class="fas fa-book fa-fw"></i>简书</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://t.me/superYang0033" title="Telegram → https:&#x2F;&#x2F;t.me&#x2F;superYang0033" rel="noopener" target="_blank"><i class="fab fa-telegram fa-fw"></i>Telegram</a>
      </span>
  </div>



      </div>

      
        <div id="music163player">
        <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=350 height=86 src="//music.163.com/outchain/player?type=2&id=31473269&auto=0&height=66">
        </iframe>
        </div>
    </div>

    

  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">SuperYang</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">157k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:23</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>













  

  

  

  <script async src="/js/cursor/fireworks.js"></script>



<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : true,
      notify     : true,
      appId      : 'zizRqalUJY55Xc5oBJKbhxpV-gzGzoHsz',
      appKey     : '64gPcVi8lIA8zVGpBSEk7uKu',
      placeholder: "留言板无需注册登录，快来评论吧。。",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
